<?php

namespace zhtfrontend\modules\teachergrowth\controllers;

use common\components\helpers\Fun;
use common\models\datas\Customer;
use common\models\datas\Student;
use doumiaoduo\aliyun\OssuploaderHelper;
use EasyWeChat\Message\Video;
use yii\console\Exception;
use yii\data\ActiveDataProvider;
use yii\db\Query;
use yii\web\UploadedFile;
use zhtfrontend\models\datas\ClassLesson;
use zhtfrontend\models\datas\ClassManage;
use zhtfrontend\models\datas\ClassManageAttribute;
use zhtfrontend\models\datas\ClassManageTeacher;
use zhtfrontend\models\datas\ClassManageTime;
use zhtfrontend\models\datas\ClassStudent;
use zhtfrontend\models\datas\LessonMedia;
use zhtfrontend\models\datas\LessonStudents;
use zhtfrontend\models\datas\Medias;
use zhtfrontend\models\datas\StudentCheck;
use zhtfrontend\models\datas\Teacher;
use zhtfrontend\modules\teachergrowth\components\rest\ActiveController;
use yii\helpers\ArrayHelper;
use yii\web\ForbiddenHttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;

class GrowthlogController extends ActiveController

{
    private $_config;
    public $modelClass = 'zhtfrontend\models\datas\ClassManage';

    public $serializer = [
        'class' => 'zhtfrontend\modules\teachergrowth\components\rest\Serializer',
        'collectionEnvelope' => 'items',
    ];

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
        return $behaviors;
    }

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'], $actions['create'], $actions['update'], $actions['delete'], $actions['view']);
        return $actions;
    }

    //下面是课程的信息包含课程的筛选;
    public function actionCourselist(){
        $data = \Yii::$app->request->get();
        $teacher_id = ArrayHelper::keyExists('teacher_id', $data) ? $data['teacher_id'] : '';
        $year = ArrayHelper::keyExists('year', $data) ? $data['year'] : '';
        $month = ArrayHelper::keyExists('month', $data) ? $data['month'] : '';
        $day = ArrayHelper::keyExists('day', $data) ? $data['day'] : '';
        $date='';
        $date_start=0;
        $date_end=0;
        if ($year!=='' && $month!=='' && $day!==''){
            $date = strtotime($year."-".$month."-".$day);
            $date_start=strtotime($year."-".$month."-".$day ."00:00:00");
            $date_end=strtotime($year."-".$month."-".$day ."24:00:00");
        }else if($month=='' && $day ==''){
            $date_start = strtotime($year."-".'01'."-".'01' ."00:00:00");
            $date_end= strtotime($year."-".'12'."-".'31' ."24:00:00");
        }else if($day=='' && $month!==''){
            $date_start = strtotime($year."-".$month."-".'01' ."00:00:00");
            $date_end= strtotime($year."-".$month."-".'31' ."24:00:00");
        }
        if (empty($teacher_id)){
            try {
                throw new ForbiddenHttpException('当前教师不存在');
            } catch (ForbiddenHttpException $e) {
                return ['statusCode' => 0, 'message' => 'error', 'result' => '当前教师不存在'];
            }
        }else{
            $course=[];
            $class_manage_teacher=ClassManageTeacher::find()->where(['teacher_id'=>$teacher_id])->asArray()->all();
            if (empty($class_manage_teacher)){
                return ['statusCode' => 201, 'message' => 'error', 'result' => '暂时没有课程'];
            }else{
                $current_class_manage=[];
                $class_ids = ArrayHelper::getColumn($class_manage_teacher, 'class_id');
                $class_manage=ClassManage::find()->where(['class_id'=>$class_ids,'status'=>[1,2]])->asArray()->all();
                foreach ($class_manage as $key=>$val){
                    $class_lesson=ClassLesson::find()->where(['class_id'=>$val['class_id']])->all();
                    $class_lesson_date=ArrayHelper::getColumn($class_lesson, 'class_date');
                    //几种情况 年月日都有 年有 年月有
                    if ($year !=='' && $month !=='' && $year ==''){ //只有年和月的情况
                        foreach ($class_lesson_date as $keys=>$vals){
                            $class_lesson_date[$keys]=date("Y-m",$vals);
                        }
                        $current_date=date("Y-m",strtotime($year.'-'.$month));
                        if (in_array($current_date,$class_lesson_date)){
                            $current_class_lesson=ClassLesson::find()->where(['class_id'=>$val['class_id']])->andWhere(['status'=>0])->one();
                            if (empty($current_class_lesson)){
                                $current_class_lesson=ClassLesson::find()->orderBy('lesson DESC')->where(['class_id'=>$val['class_id']])->andWhere(['status'=>1])->one();
                            }
                            $class_manage[$key]['current_class_lesson']=$current_class_lesson;
                        }else{
                          unset($class_manage[$key]);
                        }
                        $current_class_manage=$class_manage;
                    }else if ($year!=='' && $month!=='' && $day!==''){ //年月日都有的情况
                        foreach ($class_lesson_date as $keys=>$vals){
                            $class_lesson_date[$keys]=strtotime(date("Y-m-d ",$vals));
                        }
                        if (in_array($date,$class_lesson_date)){
                            $current_class_lesson=ClassLesson::find()->where(['class_id'=>$val['class_id']])->andWhere(['class_date'=>$date])->one();
                            $class_manage[$key]['current_class_lesson']=$current_class_lesson;
                        }else{
                          unset($class_manage[$key]);
                        }
                        $current_class_manage=$class_manage;
                    }else if($year!=='' && $month=='' && $day=='' ){ //只有年有
                        foreach ($class_lesson_date as $keys=>$vals){
                            $class_lesson_date[$keys]=date("Y",$vals);
                        }
                        if (in_array($year,$class_lesson_date)){
                            $current_class_lesson=ClassLesson::find()->where(['class_id'=>$val['class_id']])->andWhere(['class_date'=>$date])->one();
                            $class_manage[$key]['current_class_lesson']=$current_class_lesson;
                        }else{
                            unset($class_manage[$key]);
                        }
                        $current_class_manage=$class_manage;
                    }else{//全部的情况
                        $current_class_lesson=ClassLesson::find()->where(['class_id'=>$val['class_id']])->andWhere(['status'=>0])->one();
                        if (empty($current_class_lesson)){
                            $current_class_lesson=ClassLesson::find()->orderBy('lesson DESC')->where(['class_id'=>$val['class_id'],'status'=>1])->one();
                        }
                        $class_manage[$key]['current_class_lesson']=$current_class_lesson;
                        $current_class_manage=$class_manage;
                    }
                }

                if(empty($current_class_manage)){
                    return ['statusCode' => 202, 'message' => 'error', 'result' => '暂时没有课程'];
                }else{
                    foreach ($current_class_manage as $ks=>$vs){
                        switch ($vs['status']){
                            case 0:
                                $vs['status']='未开班';break;
                            case 1:
                                $vs['status']='已开班';break;
                            case 2:
                                $vs['status']='已结束';break;
                         };

                        $class_manage_attribute=ClassManageAttribute::find()->where(['class_id'=>$vs['class_id']])->one();
                        $class_manage_time=ClassManageTime::find()->where(['class_id'=>$vs['class_id']])->one();
                        $course[$vs['class_id']]=[
                            'id'=>$vs['class_id'],
                            'lesson_id'=>isset($vs["current_class_lesson"]->lesson_id)?$vs["current_class_lesson"]->lesson_id:'',
                            'course_name'=>isset($class_manage_attribute->course)?$class_manage_attribute->course:'',
                            'course_count'=>isset($vs["current_class_lesson"]->lesson)?$vs["current_class_lesson"]->lesson:'', //当前是第几节课
                            'class_time_day'=>isset($class_manage_time->class_day)?$class_manage_time->class_day:'',
                            'class_time_start'=>isset($class_manage_time->start_time)?$class_manage_time->start_time:'',
                            'class_time_end'=>isset($class_manage_time->end_time)?$class_manage_time->end_time:'',
                            'status'=>$vs['status'],
                        ];
                    }
                    $items=[
                        'course_info'=>$course,
                        'course_counts'=>count($course)
                    ];
                    return ['statusCode' => 200, 'message' => 'success', 'items' => $items];
                }
            }

        }
    }

    //下面是教学日记学生列表页面
    public function actionCoursestudent(){
        $data = \Yii::$app->request->get();
        $class_id = ArrayHelper::keyExists('class_id', $data) ? $data['class_id'] : '';
        $lesson_id = ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $class_manage_info=ClassManageAttribute::find()->where(['class_id'=>$class_id])->one();
        $class_student=ClassStudent::find()->where(['class_manage_id'=>$class_id])->asArray()->all();
        if(empty($class_student)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '当前没有学生'];
        }else{
            $first_student=Student::find()->where(['id'=>$class_student[0]['student_id']])->one();
            //需要把一键操作的状态读取出来，就是是否一键提交过
            $student_lesson_all=LessonStudents::find()->where(['lesson_id'=>$lesson_id])->one();
            //下面是是否一键上传过花絮内容
            $student_medias_all=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>0,'is_refouce'=>0])->one();
            foreach ($class_student as $key=>$val){
                $student_status='';
                $student=Student::find()->where(['id'=>$val['student_id']])->one();
                $student_check=StudentCheck::find()->where(['class_lesson_id'=>$lesson_id,'student_id'=>$val['student_id']])->one();
                $student_lesson=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$val['student_id']])->one();
                if (empty($student_check)){ //可能是没有生成签到，可能是没有这节课，可能是退课等
                    $student_status='未生成签到';
                }else{
                    switch ($student_check->status){
                        case 0:
                            $student_status='未上课或旷课';break;
                        case 1:
                            $student_status='';break;//这个地方为已签到，也就是正常状态
                        case 2:
                            $student_status='请假';break;
                        case 3:
                            $student_status='退课';break;
                        case 4:
                            $student_status='已转班';break;
                        case 5:
                            $student_status='老师请假 ';break;
                        case 6:
                            $student_status='停课';break;
                    }
                }
                //下面是喜欢度
                if (empty($student_lesson)){
                    $liking=0;
                }else{
                    $liking=!empty($student_lesson->s_course_score) ? 0:$student_lesson->s_course_score;
                }
                //下面是消息提醒（这个地方是只要是学生有反馈就显示有绿色图标）
                $feedback_media=(new Query())->select('*')->from('{{%lesson_media}}')->where(['lesson_id' => $lesson_id,'student_id'=>$val['student_id']])->all(Fun::getSiteDb());

                if (!empty($student_status)){
                    $icon_message="";
                }else{
                    if (!empty($feedback_media) || !empty($student_lesson->s_question_text)){
                        $icon_message='icon-message';
                    }else{
                        $icon_message="";
                    }
                }
                //下面是学生信息
                $student_info=[
                    'name'=>isset($student->name)?$student->name:'',
                    'nickname'=>isset($student->nickname)?$student->nickname:'',
                    'img'=>isset($student->img)?$student->img:'',
                    'status'=>$student_status,
                    'liking'=>$liking,//喜欢度
                    'completion'=>'80',//完整度
                    'icon'=>$icon_message,//消息提醒
                ];
                $class_student[$key]['student_info']=$student_info;
            }


            $t_all_content='';
            $t_all_fource='';
            $t_all_score='';
            $t_all_medias='';
            if (!empty($student_lesson_all->t_all_content)){
                $t_all_content=true;
            }
            if (!empty($student_lesson_all->t_all_fource)){
                $t_all_fource=true;
            }
            if (!empty($student_lesson_all->t_all_score)){
                $t_all_score=true;
            }
            if (isset($student_medias_all) && !empty($student_medias_all)){
                $t_all_medias=true;
            }

            $all_status=[
                't_all_content'=>$t_all_content,
                't_all_fource'=>$t_all_fource,
                't_all_score'=>$t_all_score,
                't_all_medias'=>$t_all_medias
            ];
            $class_student_list=[
                'student_count'=>count($class_student),
                'student_infos'=>$class_student,
                'class_manage_info'=>$class_manage_info,
                'first_student'=>isset($first_student) ? $first_student:'',
                'all_status'=>$all_status,
            ];
            return ['statusCode' => 200, 'message' => 'error', 'items' => $class_student_list];
        }
    }




    //需要把一键提交的信息读取出来
    public function actionGrowthallinfor(){
        $data = \Yii::$app->request->post();
        $lesson_id = ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id])->one();
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            if (empty($lesson_student)){
                return ['statusCode' => 0, 'message' => 'error', 'result' => '可备课的课程为空'];
            }else{
                $lesson_students_info=[
                    't_all_content'=>$lesson_student->t_all_content,
                    't_all_fource'=>$lesson_student->t_all_fource,
                    't_all_score'=>$lesson_student->t_all_score,
                ];
                return ['statusCode' => 202, 'message' => 'error','items' => $lesson_students_info ];
            }
        }
    }

    //下面是一键提交操作（现在是有单独的字段）
    public function actionGrowthall(){
        $data = \Yii::$app->request->post();
        $lesson_id = ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id])->all();

        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            if (empty($lesson_student)){
                return ['statusCode' => 0, 'message' => 'error', 'result' => '可备课的课程为空'];
            }else{
                if (ArrayHelper::keyExists('content_text', $data)){
                    foreach ($lesson_student as $key=>$val){
                        $val->t_all_content=$data['content_text'];
                        $lesson_student[$key]->save();
                    }
                    return ['statusCode' => 200, 'message' => 'error', 'items' => $lesson_student];
                }elseif (ArrayHelper::keyExists('fource_text', $data)){
                    foreach ($lesson_student as $key=>$val){
                        $val->t_all_fource=$data['fource_text'];
                        $lesson_student[$key]->save();
                    }
                    return ['statusCode' => 200, 'message' => 'error', 'items' => $lesson_student];
                }elseif (ArrayHelper::keyExists('feedback_score', $data)){ //这个地方就是本节课的评价，不是课下练习反馈的评价
                    foreach ($lesson_student as $key=>$val){
                        $val->t_all_score=$data['feedback_score'];
                        $lesson_student[$key]->save();
                    }
                    return ['statusCode' => 200, 'message' => 'error', 'items' => $lesson_student];
                }else{
                    return ['statusCode' => 202, 'message' => 'error','result' => '当前没有操作' ];
                }
            }
        }
    }

    //首先是把一键提交的学生花絮的信息查找出来
    public function actionFeatureallinfor(){
        $data = \Yii::$app->request->post();
        $lesson_id = ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        //查找lesson_media表里面的图片数据
        $lesson_media_image=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>0,'m_type'=>0,'is_refouce'=>0])->one();
        $medias_images_array=[];
        if (isset($lesson_media_image)){
            $medias_images=Medias::find()->where(['object_id'=>$lesson_media_image->id])->orderBy('id DESC')->limit(4)->all();
            foreach ($medias_images as $key=>$val){
                $medias_images_array[$key]=$val->file_path;
            }
        }
        $lesson_media_video=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>0,'m_type'=>1,'is_refouce'=>0])->one();
        $medias_video_src='';
        if (isset($lesson_media_video)){
            $medias_video=Medias::find()->where(['object_id'=>$lesson_media_video->id])->orderBy('id DESC')->one();
            $medias_video_src=$medias_video->file_path;
        }
        $medias_info=[
            'image'=>$medias_images_array,
            'video'=>$medias_video_src,
        ];
        return ['statusCode' => 200, 'message' => 'error', 'items' => $medias_info];
    }


    //下面是一键操作提交所有学生的花絮
    public function actionFeatureall(){
        $data = \Yii::$app->request->post();
        $lesson_id = ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id])->all();
        $image_array=ArrayHelper::keyExists('img_arrays', $data) ? $data['img_arrays'] : '';
        $video=ArrayHelper::keyExists('video_src', $data) ? $data['video_src'] : '';
        $image_arrays=json_decode($image_array);
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            if (empty($lesson_student)){
                return ['statusCode' => 0, 'message' => 'error', 'result' => '可备课的课程为空'];
            }else{
                //首先存一个总的内容吧,但是具体怎么写的简单一点还需要进一步修改啊
                $this->saveFeatures($lesson_id,0, $image_arrays,$video);
                //需要把学生的信息一条条的存进去，这个地方可能需要进行修正
                foreach ($lesson_student as $key=>$val){
                    $this->saveFeatures($lesson_id,$val->student_id, $image_arrays,$video);
                }
                return ['statusCode' => 200, 'message' => 'error', 'items' => 'success'];
            }
        }
    }

    //图片和视频上传的总的方法
    public function saveFeatures($lesson_id,$student_id,$image_array,$video){
        //首先是图片的保存
        $lesson_media_image=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'m_type'=>0,'is_refouce'=>0])->one();
        if (!empty($lesson_media_image)){
            $lesson_media_image_array=$lesson_media_image;
        }else{
            $lesson_media_image_array=new LessonMedia();
        }

        if (!empty($image_array)){
            $lesson_media_image_array->lesson_id=isset($lesson_id)?$lesson_id:'';
            $lesson_media_image_array->student_id=$student_id;
            $lesson_media_image_array->m_type=0;
            $lesson_media_image_array->is_refouce=0;
            $lesson_media_image_array->status=1;

            if ($lesson_media_image_array->save()){
                $lesson_media_image_id=$lesson_media_image_array->id;
                //下面是保存到dmd_medias表里面去
                foreach ($image_array as $keys=>$vals){
                    $medias=new Medias();
                    $medias->class_name='zhtfrontend\models\datas\LessonMedia';
                    $medias->object_id=$lesson_media_image_id;
                    $medias->file_path=$vals;
                    $medias->alt='';//现在好像没有描述
                    $medias->created_at=time();
                    $medias->updated_at=time();
                    $medias->is_default=1;
                    $medias->type=1;
                    $medias->save();
                }
            }
        }
        //然后是视频的保存
        $lesson_media_video=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'m_type'=>1,'is_refouce'=>0])->one();
        if (!empty($lesson_media_video)){
            $lesson_media_video_str=$lesson_media_video;
        }else{
            $lesson_media_video_str=new LessonMedia();
        }
        if (!empty($video)){
            $lesson_media_video_str->lesson_id=isset($lesson_id)?$lesson_id:'';
            $lesson_media_video_str->student_id=$student_id;
            $lesson_media_video_str->m_type=1;//0是图片 1是视频
            $lesson_media_video_str->is_refouce=0;//0是教师上传的花絮 1家长反馈的上课练习
            $lesson_media_video_str->status=1;
            if ($lesson_media_video_str->save()){
                $lesson_media_video_id=$lesson_media_video_str->id;
                //下面是保存到dmd_medias表里面去，视频就一条记录，就不用循环了
                $medias=new Medias();
                $medias->class_name='zhtfrontend\models\datas\LessonMedia';
                $medias->object_id=$lesson_media_video_id;
                $medias->file_path=$video;
                $medias->alt='';//现在好像没有描述
                $medias->created_at=time();
                $medias->updated_at=time();
                $medias->is_default=1;
                $medias->type=1; //1是图片 2是视频
                $medias->save();
            }
        }
    }




    //下面是学生的详情页面
    public function actionStudentdetail(){
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $class=ClassLesson::find()->where(['lesson_id'=>$lesson_id])->one();
        $student=Student::findOne($student_id);
        if (empty($student)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '学生信息未找到'];
        }else{
            //下面需要查找当前课程的上节课和下节课的信息
            if ($class->lesson >=1){
                $last_lesson_c=($class->lesson)-1;
                $next_lesson_c=($class->lesson)+1;
                $last_class_item=ClassLesson::find()->where(['class_id'=>$class->class_id,'lesson'=>$last_lesson_c])->one();
                $next_class_item=ClassLesson::find()->where(['class_id'=>$class->class_id,'lesson'=>$next_lesson_c])->one();
                //下面是上节课内容
                if (isset($last_class_item)){
                    $student_check=StudentCheck::find()->where(['class_lesson_id'=>$last_class_item->lesson_id,'student_id'=>$student_id])->one();
                    if (isset($student_check)){
                        $last_class_info=[
                            'lesson_id'=>$last_class_item->lesson_id,
                            'course_number'=>$last_class_item->lesson
                        ];
                    }else{
                        $last_class_info=[];
                    }
                }else{
                    $last_class_info=[];
                }
            //下面是下节课内容
                if (isset($next_class_item)){
                    $student_check=StudentCheck::find()->where(['class_lesson_id'=>$next_class_item->lesson_id,'student_id'=>$student_id])->one();
                    if (isset($student_check)){
                        $next_class_info=[
                            'lesson_id'=>$next_class_item->lesson_id,
                            'course_number'=>$next_class_item->lesson
                        ];
                    }else{
                        $next_class_info=[];
                    }
                }else{
                    $next_class_info=[];
                }
            }else{
                $last_class_info=[];
                $next_class_info=[];
            }
            //对性别进行判断
            if ($student->sex==0){//如果是女的话
                $sexiconBox="dmd-female-icon";
                $sexicon='icon-female';
            }else{
                $sexiconBox="dmd-male-icon";
                $sexicon='icon-male';
            }
            //需要查找一下是否打分
            $lesson_student_one=(new Query())->select('*')->from('{{%lesson_students}}')->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one(Fun::getSiteDb());
           // $lesson_student_one=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one();//只需要一条记录的
            if (isset($lesson_student_one['t_score'])&& !empty($lesson_student_one['t_score'])){
                $lesson_student_score=$lesson_student_one['t_score'];
            }elseif (isset($lesson_student_one['t_all_score'])&& !empty($lesson_student_one['t_all_score'])){
                $lesson_student_score=$lesson_student_one['t_score'];
            }else{
                $lesson_student_score=0;
            }
            //需要查看一下对学生的内容有没有单独提交过
            $prepareLesson='';
            $courseKey='';
            $feature='';

            $lesson_media_image=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'is_refouce'=>0])->one();//查找的是上课花絮，不是课下练习，所以'is_refouce'=>0

            if (isset($lesson_student_one) && (empty($lesson_student_one['t_content_text']) || $lesson_student_one['t_content_text']==null)){
                $prepareLesson='dmd-active';
            }
            if (isset($lesson_student_one) && (empty($lesson_student_one['t_fource_text']) || $lesson_student_one['t_fource_text']==null)){
                $courseKey='dmd-active';
            }

            if (isset($lesson_media_image)&& (empty($lesson_media_image) || $lesson_media_image==null)){
                $feature='dmd-active';
            }

            $upload_status=[
                'prepareLesson'=>$prepareLesson,
                'courseKey'=>$courseKey,
                'feature'=>$feature,
            ];
            $student_info=[
                'id'=>$student->id,
                'student_name'=>$student->name,
                'student_img'=>$student->img,
                'sexiconBox'=>$sexiconBox,
                'sexicon'=>$sexicon,
                'lesson_student_score'=>$lesson_student_score,
                'lastLiking'=>'70%',//上节课的喜欢度，静态数据后期要改
                'togetherLiking'=>'100%',//综合喜欢度
                'last_class_info'=>$last_class_info,
                'next_class_info'=>$next_class_info,
                'upload_status'=>$upload_status,
            ];

        }
        return ['statusCode' => 200, 'message' => 'error', 'items' => $student_info];
    }



    //下面是针对每个学生的操作,提交评分，课堂重点，课下练习重点这三个
    public function actionGrowthone(){
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one();//只需要一条记录的
            if (empty($lesson_student)){
                return ['statusCode' => 0, 'message' => 'error', 'result' => 'lesson表没有信息'];
            }else{
                if(ArrayHelper::keyExists('score', $data)){
                    $lesson_student->t_score=$data['score'];
                    $lesson_student->save();
                }elseif (ArrayHelper::keyExists('content_text', $data) ){
                    $lesson_student->t_content_text=$data['content_text'];
                    $lesson_student->save();
                }elseif (ArrayHelper::keyExists('fource_text', $data)){
                    $lesson_student->t_fource_text=$data['fource_text'];
                    $lesson_student->save();
                }
            }
            return ['statusCode' => 200, 'message' => 'error', 'items' => '成功'];
        }

    }


    //把上传的本节课的内容找出来把
    public function actionGrowthinfo(){
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one();//只需要一条记录的
            $lesson_info=[
                't_all_score'=>isset($lesson_student->t_all_score)?$lesson_student->t_all_score:'',
                't_score'=>isset($lesson_student->t_score)?$lesson_student->t_score:'',
                't_content_text'=>isset($lesson_student->t_content_text)?$lesson_student->t_content_text:'',
                't_all_content'=>isset($lesson_student->t_all_content)?$lesson_student->t_all_content:'',
                't_fource_text'=>isset($lesson_student->t_fource_text)?$lesson_student->t_fource_text:'',
                't_all_fource'=>isset($lesson_student->t_all_fource)?$lesson_student->t_all_fource:'',
            ];

            return ['statusCode' => 200, 'message' => 'error', 'items' => $lesson_info];
        }
    }


    //下面是上节课作品反馈
    public function actionFeedback(){
        $data= \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one();

            //条件 'is_refouce'=>1 表示是课下练习的反馈 'm_type'=>0表示是图片
            $lesson_media_image=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'is_refouce'=>1,'m_type'=>0])->one();
            $medias_images_array=[];
            if (isset($lesson_media_image)){
                $medias_images=Medias::find()->where(['object_id'=>$lesson_media_image->id])->orderBy('id DESC')->limit(4)->all();
                foreach ($medias_images as $key=>$val){
                    $medias_images_array[$key]=$val->file_path;
                }
            }
            $lesson_media_video=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'is_refouce'=>1,'m_type'=>1])->one();
            $medias_video_src='';
            if (isset($lesson_media_video)){
                $medias_video=Medias::find()->where(['object_id'=>$lesson_media_video->id])->orderBy('id DESC')->one();
                $medias_video_src=$medias_video->file_path;
            }

            $back_lesson_info=[
                's_question_text'=>isset($lesson_student->s_question_text)?$lesson_student->s_question_text:'',
                't_answer_text'=>isset($lesson_student)?$lesson_student->t_answer_text:'',
                't_feedback_score'=>isset($lesson_student)?$lesson_student->t_feedback_score:'',
                'medias_images_array'=>$medias_images_array,
                'medias_video_src'=>$medias_video_src,
            ];
            return ['statusCode' => 200, 'message' => 'error', 'items' => $back_lesson_info];
        }
    }

    //下面是提交课下反馈
    public function actionFeedbacksub(){
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id= ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $t_feedback_score= ArrayHelper::keyExists('t_feedback_score', $data) ? $data['t_feedback_score'] : '';
        $t_answer_text= ArrayHelper::keyExists('t_answer_text', $data) ? $data['t_answer_text'] : '';
        $t_answer_voice= ArrayHelper::keyExists('t_answer_voice', $data) ? $data['t_answer_voice'] : '';
        $second= ArrayHelper::keyExists('second', $data) ? $data['second'] : '';
        if (empty($lesson_id)){
            return ['statusCode' => 0, 'message' => 'error', 'result' => '未获取到课程信息'];
        }else{
            $lesson_student=LessonStudents::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id])->one();//只需要一条记录的
            $lesson_student->t_answer_text=$t_answer_text;
            $lesson_student->t_feedback_score=$t_feedback_score;
            //下面是语音的保存，但是现在暂时用不到
            $lesson_student->t_answer_type=$second;
            if ($t_answer_voice!==''){
                $lesson_student->t_answer_voice=$t_answer_voice;
            }
            $lesson_student->save();
            return ['statusCode' => 200, 'message' => 'error', 'items' => '成功'];
        }
    }






    //上传花絮之前把之前上传的查出来先，单个学生
    public function actionFeature(){
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';

        //查找lesson_media表里面的图片数据
        $lesson_media_image=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'m_type'=>0,'is_refouce'=>0])->one();

        $medias_images_array=[];
        if (isset($lesson_media_image)){
            $medias_images=Medias::find()->where(['object_id'=>$lesson_media_image->id])->orderBy('id DESC')->limit(4)->all();
            foreach ($medias_images as $key=>$val){
                $medias_images_array[$key]=$val->file_path;
            }
        }
        $lesson_media_video=LessonMedia::find()->where(['lesson_id'=>$lesson_id,'student_id'=>$student_id,'m_type'=>1,'is_refouce'=>0])->one();
        $medias_video_src='';
        if (isset($lesson_media_video)){
            $medias_video=Medias::find()->where(['object_id'=>$lesson_media_video->id])->orderBy('id DESC')->one();
            $medias_video_src=$medias_video->file_path;
        }
        $medias_info=[
            'image'=>$medias_images_array,
            'lesson_image_status'=>isset($lesson_media_image->status)?$lesson_media_image->status:'',
            'video'=>$medias_video_src,
            'lesson_video_status'=>isset($lesson_media_video->status)?$lesson_media_video->status:'',
        ];
        return ['statusCode' => 200, 'message' => 'error', 'items' => $medias_info];
    }


    //针对单个学生的花絮上传
    public function actionSavefeature(){
        //首先需要查找一下之前有没有上传过这个课程的花絮，如果上传的话需要修改LessonMedia表里面的信息
        $data = \Yii::$app->request->post();
        $student_id=ArrayHelper::keyExists('student_id', $data) ? $data['student_id'] : '';
        $lesson_id=ArrayHelper::keyExists('lesson_id', $data) ? $data['lesson_id'] : '';
        $image_array=ArrayHelper::keyExists('img_arrays', $data) ? $data['img_arrays'] : '';
        $video=ArrayHelper::keyExists('video_src', $data) ? $data['video_src'] : '';
        //下面是上传
        $image_arrays=json_decode($image_array);
        $this->saveFeatures($lesson_id,$student_id,$image_arrays,$video);
        return ['statusCode' => 200, 'message' => 'error', 'items' => 'success'];
    }



    //下面是录音文件的上传
    public function actionUpload(){
        $this->_config=\Yii::$app->params['aliyunoss'];
        parent::init();
        $config = array(
            "pathFormat" =>$this->_config['filePathFormat'],//filePathFormat为"/uploadfiles/web/site/file/{yyyy}{mm}{dd}/{time}{rand:6}"
            "maxSize" => $this->_config['fileMaxSize'],
            "allowFiles" => $this->_config['fileAllowFiles']
        );
        $fieldName = 'file';
        $up=new OssuploaderHelper($fieldName,$config);
        return $up->getOssFileInfo();
    }


}